package com.zhentao.day03.pm;

import java.util.Scanner;

public class StationeryTest {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);


    Shop shop = new Shop() ;


    // 死循环
    while (true) {
      System.out.println("==== 1.进货 2.售出 3.展示所有文具 4.退出 ====");
      int choose = scn.nextInt();
      switch (choose){
        case 1 :
          System.out.println("1. 添加笔  2. 添加笔记本");
          int choose1 = scn.nextInt();
          // 声明一个文具类
          Stationery stationery ;

          if(choose1 == 1) {
            // 需要添加笔进数组
            stationery = new Pen();
            System.out.println("请输入笔的名字 : ");
            String name = scn.next();
            System.out.println("请输入笔的价格 : ");
            double price = scn.nextDouble();
            System.out.println("请输入笔的数量 : ");
            int num = scn.nextInt();
            System.out.println("请输入笔的颜色 : ");
            String colorStr = scn.next();
            stationery.setName(name);
            stationery.setPrice(price);
            stationery.setNum(num);
            Pen pen = (Pen) stationery;
            pen.setColor(colorStr);
            shop.stock(pen);
          }
          if (choose1 == 2) {
            // 需要添加笔记本进数组
            stationery = new NotePad();
            System.out.println("请输入笔记本的名字 : ");
            String name = scn.next();
            System.out.println("请输入笔记本的价格 : ");
            double price = scn.nextDouble();
            System.out.println("请输入笔记本的数量 : ");
            int num = scn.nextInt();
            System.out.println("请输入笔记本的页码 : ");
            int page = scn.nextInt() ;
            stationery.setName(name);
            stationery.setPrice(price);
            stationery.setNum(num);
            NotePad notePad = (NotePad) stationery;
            notePad.setPage(page);
            shop.stock(notePad);
          }
          break;
        case 2 :
          System.out.println("请输入要售出的文具 : ");
          String name = scn.next() ;

          int i = shop.find(name);
          if(i == -1){
            System.out.println("查找的文件不存在, 请重新输入");
          }else{
            System.out.println("请输入要售出的文具数量 : ");
            int num = scn.nextInt();
            // i 下标  num 数量
            shop.sell(shop.getStationeries(),i,num);
          }
          break;
        case 3 :
          shop.show();
          break;
        case 4 :

          return;
        default:
          System.out.println("输入错误,请重新输入");
          break;
      }


    }



  }
}
